//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

typedef unsigned short UINT16;
typedef unsigned int   UINT32;
typedef unsigned char uint8_t;
typedef long           bool_t;

class DoubleLinkNode
{
public:

    // Remove myself from list. Return myself.
    DoubleLinkNode *Detach();

    // Return the previous node.
    DoubleLinkNode *Prev() const    { return m_pPrev; }
    //
    // Head-node operations
    //
    void Initialize()               { m_pPrev = m_pNext = this; }

    bool_t IsEmpty() const          { return this == m_pNext; }

    // Return the last node of list.
    DoubleLinkNode *Last()  const   { return Prev(); }

    // Insert a new node after me.  Return the new next node.
    DoubleLinkNode *InsertNext(DoubleLinkNode *pNextNode);

    // Insert a new node as the first of list. Return the new first node.
    DoubleLinkNode *InsertFirst(DoubleLinkNode *pFirstNode)
    {
        return InsertNext(pFirstNode);
    }

public:
    DoubleLinkNode      *m_pPrev;
    DoubleLinkNode      *m_pNext;
};

typedef DoubleLinkNode DLinkNode;

inline DoubleLinkNode *DoubleLinkNode::Detach()
{
    m_pPrev->m_pNext = m_pNext;
    m_pNext->m_pPrev = m_pPrev;
    m_pPrev = m_pNext = (DoubleLinkNode *)NULL;

    return this;
}

inline DoubleLinkNode *DoubleLinkNode::InsertNext(DoubleLinkNode *pNextNode)
{
    // assert(pNextNode);

    pNextNode->m_pPrev  = this;
    pNextNode->m_pNext  = m_pNext;
    m_pNext->m_pPrev    = pNextNode;
    m_pNext             = pNextNode;

    return pNextNode;
}
